package com.example.appforphysician;

import javax.security.auth.PrivateCredentialPermission;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;

public class ManagementActivity extends Activity {
	 DrawerLayout drawerLayout;
	 View drawerView;
	 TextView textPrompt, textPrompt2;

	 @Override
	 protected void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  setContentView(R.layout.activity_management);
	  
	  textPrompt = (TextView)findViewById(R.id.prompt);
	  textPrompt2 = (TextView)findViewById(R.id.prompt2);
	  
	  drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
	  drawerView = (View)findViewById(R.id.drawer);
	  
	  Button buttonOpenDrawer = (Button)findViewById(R.id.opendrawer);
	  buttonOpenDrawer.setOnClickListener(buttonOpenDrawerClickListener);
	  
	  Button buttonCloseDrawer = (Button)findViewById(R.id.closedrawer);
	  buttonCloseDrawer.setOnClickListener(buttonCloseDrawerClickListener);
	  
	  drawerLayout.setDrawerListener(myDrawerListener);
	  
	  /*
	   * In my trial experiment:
	   * Without dummy OnTouchListener for the drawView to 
	   * consume the onTouch event, touching/clicking on 
	   * un-handled view on drawView will pass to the view
	   * under it!
	   * - Touching on the Android icon will
	   * trigger the TextView("http://android-er.blogspot.com/")
	   * to open the web.
	   */

	 
	 drawerView.setOnTouchListener(new OnTouchListener(){

		@Override
		public boolean onTouch(View arg0, MotionEvent arg1) {
			// TODO Auto-generated method stub
			return false;
		}
		 
	 });
	 }
	 private View.OnClickListener buttonOpenDrawerClickListener = new View.OnClickListener() {

	        @Override
	        public void onClick(View v) {
	        	drawerLayout.openDrawer(drawerView);
	        }
	  };
	  private View.OnClickListener buttonCloseDrawerClickListener = new View.OnClickListener() {

	        @Override
	        public void onClick(View v) {
	        	drawerLayout.closeDrawers();
	        }
	  };
	 android.support.v4.widget.DrawerLayout.DrawerListener myDrawerListener = new DrawerListener() {	

		@Override
		public void onDrawerSlide(View arg0, float slideOffset) {
			// TODO Auto-generated method stub
			textPrompt.setText("onDrawerSlide: " + String.format("%.2f", slideOffset));
		}
		
		@Override
		public void onDrawerOpened(View arg0) {
			// TODO Auto-generated method stub
			textPrompt.setText("onDrawerOpened");
		}
		
		@Override
		public void onDrawerClosed(View arg0) {
			// TODO Auto-generated method stub
			textPrompt.setText("onDrawerClosed");
		}
		@Override
		public void onDrawerStateChanged(int newState) {
			// TODO Auto-generated method stub
			 String state;
			   switch(newState){
				   case DrawerLayout.STATE_IDLE:
				    state = "STATE_IDLE";
				    break;
				   case DrawerLayout.STATE_DRAGGING:
				    state = "STATE_DRAGGING";
				    break;
				   case DrawerLayout.STATE_SETTLING:
				    state = "STATE_SETTLING";
				    break;
				   default:
				    state = "unknown!";
			    }
			    textPrompt2.setText(state);
		}
	};
	

}